set(CMAKE_SYSTEM_NAME Generic)       #利用cmake进行交叉编译必须设置的,如果要创建运行在没有操作系统的嵌入式环境，该参数要设置成Generic
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
cmake_minimum_required(VERSION 3.20)

# 工具链设置
set(TOOLPATH aarch64-none-linux-gnu-)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) #生成compile_commands.json

if (WIN32)
	MESSAGE(STATUS "Now is windows!")
    set(CMAKE_C_COMPILER ${TOOLPATH}gcc.exe)
    set(CMAKE_CXX_COMPILER ${TOOLPATH}g++.exe)
    set(CMAKE_ASM_COMPILER ${TOOLPATH}gcc.exe)
    set(CMAKE_AR ${TOOLPATH}ar.exe)
    set(CMAKE_OBJCOPY ${TOOLPATH}objcopy.exe)
    set(CMAKE_OBJDUMP ${TOOLPATH}objdump.exe)
    set(SIZE ${TOOLPATH}size.exe)
elseif (UNIX)
	MESSAGE(STATUS "Now is UNIX-like OS!")
    set(CMAKE_C_COMPILER ${TOOLPATH}gcc)
    set(CMAKE_CXX_COMPILER ${TOOLPATH}g++)
    set(CMAKE_ASM_COMPILER ${TOOLPATH}gcc)
    set(CMAKE_AR ${TOOLPATH}ar)
    set(CMAKE_OBJCOPY ${TOOLPATH}objcopy)
    set(CMAKE_OBJDUMP ${TOOLPATH}objdump)
    set(SIZE ${TOOLPATH}size)
    add_definitions(-D__linux__ -D__linux)
else ()
    MESSAGE(STATUS "Unsupported system!")
endif ()

# 项目设置
project(media LANGUAGES "C" "CXX" "ASM") #指定语言为c、c++和汇编，如果不设置LANGUAGES，则默认为c、c++

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)

# 编译参数 一般不用改
#add_compile_options(-mcpu=cortex-m3 -mthumb)

#调试信息
add_compile_options(-g -gdwarf-2)

# 编译等级
add_compile_options(-O2)

# 编译信息等级
add_compile_options(-Wall)

# 头文件路径
include_directories(src
                    src/net
                    src/xop
                    src/3rdpart
                    src/camera
                    src/encoder
                    include/)

# 宏定义
#add_definitions(-DDEBUG=1)

# 源码文件
file(GLOB_RECURSE SOURCES 
                "src/*.cpp"
                "src/xop/*.cpp" 
                "src/net/*.cpp"
                "src/camera/*.cpp"
                "src/encoder/*.cpp"
                )

# 链接参数
#自定义链接库路径
link_directories(lib/)
#自定义链接库
set(LINKER_LIBS -lrt -pthread -lpthread -ldl -lm -lx264)
add_link_options(${LINKER_LIBS})

# 编译可执行文件
add_executable(${PROJECT_NAME} ${SOURCES} ${LINKER_SCRIPT})

# 链接静态库
target_link_libraries(${PROJECT_NAME} ${LINKER_LIBS})

